home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_confirmer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  5.8 KB  |  218 lines

  1. /*****************************************************************************
  2.   FILE           : ui_confirmer.c
  3.   SHORTNAME      : confirm.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        :
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 6.7.1990
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)ui_confirmer.c    1.12 3/2/94
  14.   SCCS VERSION   : 1.12
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include "ui.h"
  23.  
  24. #include <X11/Shell.h>
  25. #include <X11/Xaw/Command.h>
  26. #include <X11/Xaw/Form.h>
  27. #include <X11/Xaw/Label.h>
  28.  
  29. #include "ui_main.h"
  30. #include "ui_mainP.h"
  31. #include "ui_xWidgets.h"
  32.  
  33. #include "stopIcon.xbm"
  34. #include "exclamation.xbm"
  35.  
  36. #include "ui_confirmer.ph"
  37.  
  38.  
  39. /*****************************************************************************
  40.   FUNCTION : ui_cf_yesNoOk
  41.  
  42.   PURPOSE  : terminating of the confirmer
  43.   RETURNS  : void
  44.   NOTES    :
  45.  
  46.   UPDATE   :
  47. *****************************************************************************/
  48.  
  49. static void ui_cf_yesNoOk (Widget widget, caddr_t client_data, 
  50.         caddr_t call_data)
  51.  
  52. {
  53.     XtDestroyWidget(ui_cf_popup);
  54.     ui_cf_answer = (int) client_data;
  55.     ui_cf_exit   = TRUE;
  56. }
  57.  
  58.  
  59. /*****************************************************************************
  60.   FUNCTION : ui_confirm
  61.  
  62.   PURPOSE  : Built and display the confirmer, get a return value (which button
  63.              was pressed, kill the window and return the value to the caller.
  64.   RETURNS  : which button was pressed by the user.
  65.   NOTES    : 
  66.  
  67.   UPDATE   :
  68. *****************************************************************************/
  69.  
  70. static void ui_confirm (char *message, int ok_only)
  71.  
  72. {
  73.     Widget      form, picture, label;
  74.     Arg        args[5];
  75.     Widget    button;
  76.     Cardinal    n;
  77.     XEvent      event;
  78.  
  79.     /* Now create Popup */
  80.  
  81.     ui_cf_popup = 
  82.     XtCreatePopupShell("confirmer", transientShellWidgetClass, ui_toplevel,
  83.                NULL, 0);
  84.     form = 
  85.     XtCreateManagedWidget("form", formWidgetClass, ui_cf_popup, NULL, 0);
  86.  
  87.     if (ok_only) {
  88.     n = 0;
  89.     XtSetArg(args[n], XtNborderWidth, 0); n++;
  90.     XtSetArg(args[n], XtNbitmap, 
  91.          (Pixmap) XCreateBitmapFromData(ui_display, 
  92.                         XDefaultRootWindow(ui_display),
  93.                         exclamation_bits, exclamation_width,
  94.                         exclamation_height)); n++;
  95.         picture = 
  96.         XtCreateManagedWidget("exclamation", labelWidgetClass, form, 
  97.                   args, n);     
  98.  
  99.     n = 0;
  100.     XtSetArg(args[n], XtNfromHoriz, picture); n++;
  101.     XtSetArg(args[n], XtNborderWidth, 0); n++;
  102.     XtSetArg(args[n], XtNlabel,     message); n++;
  103.     label = 
  104.         XtCreateManagedWidget("confirmerMsg", labelWidgetClass, form, args, n);
  105.     
  106.     button = ui_xCreateButtonItem("ok", form, picture, label);
  107.     XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
  108.             (caddr_t) TRUE);
  109.  
  110.     } else {
  111.     n = 0;
  112.     XtSetArg(args[n], XtNborderWidth, 0); n++;
  113.     XtSetArg(args[n], XtNbitmap, 
  114.          (Pixmap) XCreateBitmapFromData(ui_display, 
  115.                         XDefaultRootWindow(ui_display),
  116.                         stopIcon_bits, stopIcon_width,
  117.                         stopIcon_height)); n++;
  118.     picture =
  119.         XtCreateManagedWidget("stop", labelWidgetClass, form, 
  120.                   args, n);
  121.  
  122.     n = 0;
  123.     XtSetArg(args[n], XtNfromHoriz, picture); n++;
  124.     XtSetArg(args[n], XtNborderWidth, 0); n++;
  125.     XtSetArg(args[n], XtNlabel,     message); n++;
  126.     label = 
  127.         XtCreateManagedWidget("confirmerNsg", labelWidgetClass, form, 
  128.                   args, n);
  129.  
  130.     button = ui_xCreateButtonItem("yes", form, picture, label);
  131.     XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
  132.             (caddr_t) TRUE);
  133.  
  134.     button = ui_xCreateButtonItem("no", form, button, label);
  135.     XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
  136.             (caddr_t) FALSE);
  137.     }
  138.     XawFormDoLayout(form, True);
  139.     XtRealizeWidget(ui_cf_popup);
  140.     
  141.     /* now move the popup to the middle of the screen */
  142.     {
  143.     Window root;
  144.     int    x, y;
  145.     unsigned int borderWidth, depth, width, height;
  146.     XWindowChanges xChange;
  147.     
  148.     (void) XGetGeometry(ui_display, XtWindow(ui_cf_popup),
  149.                 &root, &x, &y, &width, &height, &borderWidth, &depth);
  150.     
  151.     xChange.x = 
  152.         (int) ((XDisplayWidth(ui_display, ui_screen) - width) / 2);
  153.     xChange.y =
  154.         (int) ((XDisplayHeight(ui_display, ui_screen) - height) / 2);
  155.     xChange.stack_mode = (int) Above;
  156.     XConfigureWindow(ui_display, XtWindow(ui_cf_popup), 
  157.              CWX BIT_OR CWY BIT_OR CWStackMode, &xChange);
  158.     }
  159.  
  160.     XtPopup(ui_cf_popup, XtGrabExclusive);
  161.     ui_xDontResizeWidget(ui_cf_popup); 
  162.  
  163.     /* now enter the confirmer loop.
  164.        Everthing behaves the same, because its an copy of XtAppMainLoop(), 
  165.        but it stops UI from processing code from here back to the main loop.
  166.        This is needed, because the confirmer should return values! */
  167.  
  168.     ui_cf_exit = FALSE;
  169.     while (NOT ui_cf_exit) {
  170.     XtAppNextEvent(ui_appContext, &event);
  171.     (void) XtDispatchEvent(&event);
  172.     }
  173. }
  174.  
  175.  
  176. /*****************************************************************************
  177.   FUNCTION : ui_confirmYes
  178.  
  179.   PURPOSE  : call the confirmer whith buttons NO and YES and STOP sign
  180.   RETURNS  : TRUE, if the user pressed the YES button, else FALSE;
  181.   NOTES    :
  182.  
  183.   UPDATE   :
  184. *****************************************************************************/
  185.  
  186. int ui_confirmYes (char *message)
  187.  
  188. {
  189.     ui_confirm(message, FALSE);
  190.     return(ui_cf_answer);
  191. }
  192.  
  193.  
  194. /*****************************************************************************
  195.   FUNCTION :  ui_confirmOk
  196.  
  197.   PURPOSE  : call the confirmer with button OK and a exclamation mark icon.
  198.   RETURNS  : void.
  199.   NOTES    : This routine is used to show important messages to the user.
  200.              Don't use it to much, because the user will become nervous!
  201.  
  202.   UPDATE   :
  203. *****************************************************************************/
  204.  
  205. void ui_confirmOk (char *message)
  206.  
  207. {
  208.     ui_confirm(message, TRUE);
  209. }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /* end of file */
  217. /* lines: 225 */
  218.